// pages/Search/list/list.js
var app = getApp();
var ikz = require('../../Common/tools.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    search_info: [],//搜索到的信息
    page: 1,//页数
    limit: 6,//每页条数
    options: '',//搜索条件
    prodis: 'none',//底部提示是否显示
  },
  //查看地图位置
  openMap: function (e) {
    console.log(e)
    var latitude = parseFloat(e.currentTarget.dataset.latitude);
    var longitude = parseFloat(e.currentTarget.dataset.longitude);
    console.log(latitude)
    console.log(longitude)
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
    })
  },
  //拨打电话
  toPhone: function (e) {
    var phone = e.currentTarget.dataset.pho;
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    ikz.over(this);
    this.setData({
      options: options,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var input_value = this.data.options.input_value;
    var tyid = this.data.options.tyid;
    var twid = this.data.options.twid;
    var page = 1;
    var limit = this.data.limit;
    var that = this;
    var path = 'Search/searchInfo';
    var data = {
      tyid: tyid,
      twid: twid,
      input_value: input_value,
      page: page,
      limit: limit,
    }
    console.log(data)
    ikz.request(path, data, false, (res) => {
      console.log(res.data)
      console.log(3131)
      if (res.data.status == 'success') {
        that.setData({
          search_info: res.data.search_info,
          page: page,
        });
        ikz.hide(that);
      } else {
        wx.showModal({
          title: '提示',
          content: '服务器繁忙，请稍后重试！',
          showCancel: false
        })
      }

    });
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载中',
    });
    var page = this.data.page + 1;
    var options = this.data.options;
    var old_info = this.data.search_info;
    this.setData({
      page: page,
    })
    var input_value = options.input_value;
    var rid = options.rid;
    var tyid = options.tyid;
    var twid = options.twid;
    var limit = this.data.limit;
    var that = this;
    var path = 'Search/searchInfo';
    var data = {
      rid: rid,
      tyid: tyid,
      twid: twid,
      input_value: input_value,
      page: page,
      limit: limit,
    }
    ikz.request(path, data, false, (res) => {
      console.log(res)
      console.log(34344)
      if (res.data.status == 'success') {
        var new_info = res.data.search_info;
        if (new_info.length) {
          var all_info = old_info.concat(new_info);
          var prodis = 'none';
        } else {
          var all_info = old_info;
          var prodis = 'block';
        }
        that.setData({
          search_info: all_info,
          options: options,
          prodis: prodis,
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '服务器繁忙，请稍后重试！',
          showCancel: false
        })
      }

    });
    wx.hideLoading();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})


